<?php

//aksi perubahan status
if(isset($_POST['submit'])){
	
	$QCheck=mysql_query("SELECT IDOrder FROM OrderData WHERE IDOrde='".$_POST['IDOrder']."'");
//cek kestersediaan idorder

	if(mysql_num_rows($QCheck)){
		$Update=mysql_query("UPDATE OrderData SET StatusOrder='".$_POST['StatusOrder'])."' WHERE IDOrder='".$_POST['IDOrder']."'" OR die('Error');

		//echo $_POST['IDOrder'].'-
	'.$_POST['StatusOrder'];
		echo "<meta http-equiv=\"refresh\" content=\"0;url=".$_SERVER['PHP_SELF']."?v=order&act=proses&IDOrder=".$_POST['IDOrder']."\">";
		exit;
	}
	else{
		echo 'perhintah gagal dilakukan. ulangi lagi.';
	}

	$GIDOrder=$_GET['IDOrder'];
	$DataStatus=array("baru","lunas","terkirim");

	$Order=mysql_query("SELECT o.IDOrder, o.TanggalOrder, o.StatusOrder, 
		d.JumlahBeli, b. ISBN, b.judul, b.harga, m.NamaLengkap, m.Alamat FROM OrderData o, DetailOrder d, member m, buku b WHERE o.IDOrder=d.IDOrder and m.username=o.Username and LevelMember='member' and o.IDOrder='".$GIDOrder."'") OR DIE(mysql_error());

	if(mysql_num_rows($Order)) {
		echo "<table align='center' width='610'> colspan='6'>Informasi Produk</th></tr>
		<tr>
		bgcolor='#92a751'><th>No</th><th>ISBN</th><th>SEPATU</th><th>Harga</th><th>Jml</th><th>Subtotal</th>
		</tr>";
		$Tot=0;
		$No=1;
		while($r=mysql_fetch_array($QOrder)){
			$IDOrder=$r['IDOrder'];
			$TglOrder=$r['TanggalOrder'];
			$StatususOrder=$r['Statusorder'];
			$JmlBeli=$r['JumlahBeli'];
			$ISBN=$r['ISBN'];
			$Harga=$r['Harga'];
			$Judul=$r['Judul'];
			$NamaLengkap=$r['NamaLengkap'];
			$Alamat=$r['Alamat'];
			$SubTotal=$Harga*$JmlBeli;
			$Tot=$Tot+$SubTotal;

			if($No % 2==0) {
				echo "<tr bgcolor='#d8dfea'>";
			}
			else {
				echo "<tr bgcolor='#edeff4'>";
			}
			echo "<td>$No</td><td>$ISBN</td><td>$Judul</td><td>Rp".number_format($Harga,2,",",".")."</td><td>$JmlhBeli</td><td align='right'>Rp ".number_format($SubTotal,2,",",".")."</td></tr>";

			$No++;
		}
		echo "<tr bgcolor='#92a751'><th colspan='4' align='right'>Total</th><th colspan='2' align='right'>Rp".number_format($Tot,2,",",".").</th></tr>;
		echo "<tr><td colspan='6' height='20'>&nbsp;</td></tr><tr><tr bgcolor='#d8dfea'><th colspan='6'>Informasi Pembeli</th></tr>
		<tr bgcolor='#edeff4'><td colspan='3'>IDOrder</td><td colspan='3'>$IDOrder</td></tr>
		<tr bgcolor='#d8dfea'><td colspan='3'>Tanggal</td><tdcolspan='3'>$TglOrder</td></tr><tr bgcolor='edeff4'><td colspan='3'>Nama</td><td colspan='3'>$NamaLengkap</td></tr>
		<tr bgcolor='#d8dfea'><td colspan='3'>Alamat</td><td colspan='3'>$Alamat</td></tr>
		<tr bgcolor='#edeff4'><td colspan='3'>Status</td><td colspan='3'>

		<form action='$_SERVER[PHP_SELF]?v=order&act=proses'method='POST'>
		<input type='hidden' name='IDOrder' value='$IDOrder'>
		<selct name='StatusOrder'>";
		foreach($DataStatus AS $Key=>$Val){
			if($StatusOrder==$Val){
				echo "<option value='$Val' selected>".strtoupper($Val)."</option>";
			}
			else{
				echo "<option value='$Val'>".strtoupper($Val)."</option>";
			}
		}
		echo "</select></td></tr>
		<tr><td colspan='6' align='right'><input type='submit' value='Update status' name='submit'/></td></tr>
		</table>
		</form>";
		}

		else{
			echo 'Maaf, data tidak di temukan.';
		}
?>